﻿using System;
using System.Xml.Serialization;

namespace AOUtils.Libraries
{
    public class Item
    {
        [XmlAttribute("AOID")]
        public int Id
        {
            get;
            set;
        }
        [XmlAttribute]
        public string Name
        {
            get;
            set;
        }
        [XmlAttribute("QL")]
        public int Ql
        {
            get;
            set;
        }
        [XmlAttribute("ItemType")]
        public ItemType Type
        {
            get;
            set;
        }
        [XmlAttribute("IsNano")]
        public string IsNanoString
        {
            get;
            set;
        }
        public bool IsNano
        {
            get
            {
                return bool.Parse(IsNanoString);
            }
        }
        public int Icon
        {
            get
            {
                if (Attributes.Contains("Icon"))
                    return int.Parse(Attributes["Icon"].Value);
                return 0;
            }
        }
        [XmlElement("Attribute", typeof(Attribute))]
        public AttributeCollection Attributes
        {
            get;
            set;
        }
        [XmlElement("AtkValue", typeof(AttackValue))]
        public AttackValueCollection AttackValues
        {
            get;
            set;
        }
        [XmlElement("Event", typeof(Event))]
        public EventCollection Events
        {
            get;
            set;
        }
        [XmlElement("Action", typeof(Action))]
        public ActionCollection Actions
        {
            get;
            set;
        }
        [XmlIgnore]
        public Flags Flags
        {
            get
            {
                if (Attributes.Contains("Flags"))
                    return (Flags)Enum.Parse(typeof(Flags), Attributes["Flags"].Value);
                return Flags.None;
            }
        }
        [XmlIgnore]
        public Slot Slot
        {
            get
            {
                if (Attributes.Contains("Slot"))
                    return (Slot)Enum.Parse(typeof(Slot), Attributes["Slot"].Value);
                return Slot.None;
            }
        }
        [XmlIgnore]
        public EquipmentPage EquipmentPage
        {
            get
            {
                if (Attributes.Contains("EquipmentPage"))
                    return (EquipmentPage)Enum.Parse(typeof(EquipmentPage), Attributes["EquipmentPage"].Value);
                return EquipmentPage.None;
            }
        }
        [XmlIgnore]
        public int MultiRanged
        {
            get
            {
                if (Attributes.Contains("MultiRanged"))
                    return (int)int.Parse(Attributes["MultiRanged"].Value);
                return 0;
            }
        }
        [XmlIgnore]
        public int MultiMelee
        {
            get
            {
                if (Attributes.Contains("MultiMelee"))
                    return (int)int.Parse(Attributes["MultiMelee"].Value);
                return 0;
            }
        }
    }
}
